package org.example.main;

import java.util.regex.*;

public class Main {
    public static void main(String[] args) {
        String input = "变流器1ACC元件总故障,变流器1ACC的U相上管故障,变流器1ACC的U相下管故障,变流器1ACC的V相上管故障,变流器1ACC的W相上管故障";
        String input1  = "ACC元件总故障,ACC的U相上管故障,ACC的U相下管故障";
        String input2 = "ACC元件总故障,ACC的U相上管故障,ACC的U相下管故障,ACC的V相上管故障,ACC的W相上管故障";
        String input3 = "ACC元件总故障,ACC的U相上管故障,ACC的V相上管故障,ACC的W相上管故障,ACC的W相下管故障";
        String input4 = "AL3元件总故障,L3A相上管故障,L3B相上管故障,L3C相上管故障,L3C相下管故障";
        String input5 = "M1元件总故障,M1A相上管故障,M1A相下管故障,M1C相上管故障,M1D相上管故障";
        String input6 = "L2元件总故障,L2A相上管故障,L2A相下管故障,L2C相上管故障,L2D相上管故障";
        String input7 = "L1元件总故障,L1A相上管故障,L1A相下管故障,L1C相上管故障,L1D相上管故障";
        String in8 ="主变流器1L1元件总故障,主变流器1L1A相上管故障,主变流器1L1B相下管故障,主变流器1L1C相上管故障,主变流器1L1D相下管故障";

        //String regex = "(?<=变流器[\\d]+[A-Z]{0,1}[A-Z]{0,1}[A-Z]{0,1}元件总故障,[\\s]*)(变流器[\\d]+[A-Z]{0,1}[A-Z]{0,1}[A-Z]{0,1}([UVW])[\\s]*相上管故障,[\\s]*变流器[\\d]+[A-Z]{0,1}[A-Z]{0,1}[A-Z]{0,1}\\2相下管故障([\\s]*,[\\s]*变流器[\\d]+[A-Z]{0,1}[A-Z]{0,1}[A-Z]{0,1}([UVW])[\\s]*相上管故障,[\\s]*变流器[\\d]+[A-Z]{0,1}[A-Z]{0,1}[A-Z]{0,1}\\4相下管故障)*)";
        String regex = "^主变流器\\d+[A-Z]*元件总故障(?:,主变流器\\d+[A-Z]*(?:[A-Z]*(?:相上|相下)管故障(?:,|$)))+$\n";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(input1);

        if (matcher.find()) {
            System.out.println(matcher.group(0));
        }else {
            System.out.println("======");
        }
    }
}
